package com.yycx.module.bus.provider.handler.process.listener;

import com.yycx.common.constants.CommonConstants;
import com.yycx.common.utils.ApiAssert;
import com.yycx.module.bus.client.entity.BusOrderDetails;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.provider.service.*;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 回款审批结束监听器
 *
 * @author zyf
 */
@Component
public class HuikuanProcessEndListener implements TaskListener {

    @Resource
    private BusPaymentService paymentService;

    @Resource
    private BusOrderDetailsService orderDetailsService;
    @Override
    public void notify(DelegateTask delegateTask) {
        String businessKey = delegateTask.getVariable("businessKey", String.class);

        BusPayment payment = paymentService.getById(businessKey);
        BusOrderDetails orderDetails = orderDetailsService.getById(payment.getOrderDetailsId());
        ApiAssert.isNotEmpty("回款信息不存在", orderDetails);

        payment.setPaymentState(CommonConstants.INT_2);
        //更新为已审批状态
        paymentService.updateById(payment);

        //更新明细表中回款信息
        orderDetailsService.updateHuikuanInfo(payment);
    }
}
